import { uploadFile } from '../controller/file'
import multer from 'multer'
import { resultWrapper } from '../util/common'
import { interceptor } from './interceptor'
import conf from '../config/conf.js'

const upload = multer({dest: conf.uploadTmpDir})

export default app => {
  // 上传文件
  app.post('/file/upload', upload.any(), interceptor({
    isNeedLock: true,
    func: async (req, res) => {
      let {data, message} = await uploadFile(req, res)
      res.send(resultWrapper(data, message))
      return data
    }
  }))
}
